package com.mdd.admin.task;

import com.mdd.admin.service.order.IOrderRefundService;
import com.mdd.common.entity.system.SystemDevCrontab;
import com.mdd.common.mapper.system.SystemDevCrontabMapper;
import com.mdd.common.utils.TimeUtil;

import java.util.Objects;

public class RefundOrderCheckRunnable implements Runnable {

    private int id;
    private String name;
    private IOrderRefundService iOrderRefundService;

    private SystemDevCrontabMapper systemDevCrontabMapper;

    public RefundOrderCheckRunnable(int id, String name, IOrderRefundService iOrderRefundService, SystemDevCrontabMapper systemDevCrontabMapper) {
        this.id = id;
        this.name = name;
        this.iOrderRefundService = iOrderRefundService;
        this.systemDevCrontabMapper = systemDevCrontabMapper;
    }

    @Override
    public void run() {
        SystemDevCrontab systemDevCrontab = systemDevCrontabMapper.selectById(id);
        systemDevCrontab.setLastTime(TimeUtil.timestamp());
        systemDevCrontab.setUpdateTime(TimeUtil.timestamp());
        this.systemDevCrontabMapper.updateById(systemDevCrontab);
        this.iOrderRefundService.checkStatus();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        RefundOrderCheckRunnable that = (RefundOrderCheckRunnable) o;
        return id == that.id;
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
